// Copyright (c) 2025 Huawei Technologies Co., Ltd.
// openUBMC is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
//         http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
//
// Description: 实现kvm客户端认证提供创建会话的能力
#pragma once

#include <vector>
#include "ClientBaseHttp.hpp"

using HttpSuccInfo = struct {
    std::string title;
    char* sessionId;
    char* token;
    std::string kvmIp;
    std::int64_t kvmPort;
    std::vector<std::string> privilege;
};

class ClientAuthentication : public ClientBaseHttp {

public:
    explicit ClientAuthentication();
    ~ClientAuthentication() override;

    // 取得请求体body
    void GetReqBody(boost::string_view userName, const char* passWord, boost::string_view kvmMode);
    // 创建会话
    bool CreateSessionFromWeb(boost::string_view host, boost::string_view port, boost::string_view userName,
        const char* passWord);
    HttpSuccInfo GetSuccInfo();
    boost::string_view GetToken();
    boost::string_view GetSessionId();

private:
    void ParseSuccInfo() override;
    void ResetSuccRes() override;

private:
    HttpSuccInfo succRes_;
    // 记录最后一次成功创建会话的session信息，删除会话时使用
    char* lastSuccToken_;
    char* lastSuccSessionId_;
};
